package com.tarena.lbs.basic.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.pojo.vo.AreaVO;
import com.tarena.lbs.basic.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处理区域 地市数据业务的接口类
 */
@Tag(name = "区域服务", description = "区域服务")
@RestController
@Slf4j
public class AreaController {
    @Autowired
    private AreaService areaService;

    @Operation(summary = "查询省级地区列表")
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> queryProvinces() {
        //查询省级别的地区列表    查询条件 parentId = 0
        List<AreaVO> areaList = areaService.selectAreaList(0);
        log.info("查询省级列表:{}", areaList);
        return new Result<>(areaList);
    }

    @Operation(summary = "查询地市列表")
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> queryChildren(@PathVariable("parentId") Integer parentId) {
        //查询地市列表
        log.info("查询地市列表，省级id:{}", parentId);
        List<AreaVO> childrenList = areaService.selectChildrenList(parentId);
        log.info("查询地市列表，子级列表:{}", childrenList);
        return new Result<>(childrenList);
    }

    @Operation(summary = "查询地市树")
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> tree() {
        List<AreaVO> treeList = areaService.selectreeList();
        log.info("查询地市树:{}", treeList);
        return new Result<>(treeList);
    }
}
